﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Hook.Graphics;
using Microsoft.Xna.Framework.Graphics;

namespace Hook.Environmental.Effects
{
    public class GameEffect
    {
        public const int BACKGROUND = 0;
        public const int MIDGROUND = 1;
        public const int FOREGROUND = 2;

        public Sprite Sprite;
        public Vector3 Position, Velocity, Acceleration;
        public Vector3 Rotation, AngularVelocity, AngularAcceleration;
        public bool GravityOn, RepeatOn, Removing;
        public int DrawPriority;

        public List<GameEffect> Effects;

        /// <summary>
        /// Generates the default values for an effect.
        /// </summary>
        public GameEffect()
        {
            Position = Velocity = Acceleration = Vector3.Zero;
            Rotation = AngularVelocity = AngularAcceleration = Vector3.Zero;
            GravityOn = false;
            Effects = new List<GameEffect>();
            DrawPriority = MIDGROUND;
        }

        public void Update(GameTime gt)
        {
            foreach (GameEffect E in Effects)
                E.Update(gt);

            Position += Velocity += Acceleration;
            Rotation += AngularVelocity += AngularAcceleration;

            if (Sprite != null)
            {
                Sprite.Position = Position;
                Sprite.Rotation = Rotation;
                int FrameNumber = Sprite.CurrentFrame;
                Sprite.Update(gt);
                if (!RepeatOn && FrameNumber > Sprite.CurrentFrame)
                    Removing = true;
            }
        }
        public void Draw(SpriteBatch sb, Camera Cam)
        {
            foreach (GameEffect E in Effects)
                E.Draw(sb, Cam);

            if (Sprite != null)
                Sprite.Draw(sb, Cam);
        }
    }
}
